package hn.sigit.view.workflow.transaction;

import java.io.Serializable;

import javax.faces.model.SelectItem;

import hn.sigit.model.hnd.cadastre.HND_TaxStatusType;
import hn.sigit.model.hnd.ladmshadow.Parcel;
import hn.sigit.dao.hnd.ladmshadow.ParcelDAO;


public class DataEntryParcelDataHelper implements Serializable {
	private static final long serialVersionUID = 1L;

	private DataEntryHelper dataEntryHelper;
	
	private SelectItem[] taxStatusTypes;
	private boolean editing = false;
	

	public DataEntryParcelDataHelper(DataEntryHelper dataEntryHelper) {
		this.dataEntryHelper = dataEntryHelper; 
	}
	
	public String beginEditData() {
		editing = true;
		return null;
	}
	
	public String cancelEditData() {
		editing = false;
		return null;
	}
	
	public String applyDataChange() {
		Parcel parcel = (Parcel) dataEntryHelper.getSelectedParcel();
		if (parcel != null) {
			parcel.setModified(true);
			parcel.setOriginal(false);
			ParcelDAO.save(parcel);
			editing = false;
		}
		return null;
	}

	public boolean isEditing() {
		return editing;
	}
	
	public SelectItem[] getTaxStatusTypes() {
		if (taxStatusTypes == null) {
			HND_TaxStatusType[] hndTaxStatusTypes = HND_TaxStatusType.values();
			taxStatusTypes = new SelectItem[hndTaxStatusTypes.length];
			HND_TaxStatusType htst;
			for (int i = 0; i < taxStatusTypes.length; i++) {
				htst = hndTaxStatusTypes[i];
				taxStatusTypes[i] = new SelectItem(htst, dataEntryHelper.getResBundle().loadMessage(htst.name()));
			}
		}
		return taxStatusTypes;
	}
	
	public String getCurrentLandUseName() {
		if (dataEntryHelper.getSelectedParcel() == null
				|| dataEntryHelper.getSelectedParcel().getCurrentLandUse() == null)
			return "";
		
		return dataEntryHelper.getSelectedParcel().getCurrentLandUse().getFullName();
	}
	public void setCurrentLandUseName(String landUseName) {
	}
	
	public String getProposedLandUseName() {
		if (dataEntryHelper.getSelectedParcel() == null
				|| dataEntryHelper.getSelectedParcel().getCurrentLandUse() == null)
			return "";
		return dataEntryHelper.getSelectedParcel().getProposedLandUse().getFullName();
	}
	public void setProposedLandUseName(String landUseName) {
	}

}
